<%- partial('../editor_sidebar') %>

<div id='content'>
  <div class='panel'>
    <div class='header'>
      <ol class='breadcrumb'>
        <li><a href='/'>主页</a><span class='divider'>/</span></li>
        <% if(typeof(action) !== 'undefined' && action == 'edit'){ %>
        <li class='active'>编辑记录 <%= typeof(eam_wo_id) !== 'undefined' && eam_wo_id || '' %></li>
        <% }else{ %>
        <li class='active'>发布记录</li>
        <% } %>
      </ol>
    </div>
    <div class='inner post'>
      <% if(typeof(edit_error) !== 'undefined' && edit_error){ %>
      <div class="alert alert-error">
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong><%= edit_error %></strong>
      </div>
      <% } %>
      <% if(typeof(error) !== 'undefined' && error){ %>
      <div class="alert alert-error">
        <strong><%= error %></strong>
      </div>
      <% }else{ %>
      <% if (typeof(action) !== 'undefined' && action === 'edit') { %>
      <form id='create_schedule_form' action='/modules/schedule/<%= topic_id %>/edit' method='post'>
        <% } else { %>
        <form id='create_schedule_form' action='/modules/schedule/create' method='post'>
          <% } %>
          <fieldset>
            <span class="tab-selector">选择类型：</span>
              <% if (typeof(topic_id) !== 'undefined') { %>
                <select name="tab" id="tab-value" disabled>
              <% }else{ %>
                <select name="tab" id="tab-value">
              <% } %>
              <option value="">请选择</option>
              <%
              var tabValue = '';
              if (typeof(tab) !== 'undefined') {
                tabValue = tab;
              }
              tabs.forEach(function (pair) {
                var value = pair[0];
                var text = pair[1];
                %>
                <option value="<%=value%>" <%= tabValue === value ? 'selected': '' %>><%=text%></option>

              <%});%>
            </select>
            <span id="topic_create_warn"></span>
            <div class="form-group">
              <label for="schedule_name" class="name_label">名称（必填）</label>
              <input name="schedule_name" type="text" class="form-control" id="schedule_name" placeholder="" value="<%= typeof(schedule_name) !== 'undefined' && schedule_name || '' %>">
            </div>
            <div class="form-group">
              <label for="schedule_description">内容描述（选填）</label>
              <textarea class='editor' name='schedule_description' rows='10'
                          placeholder=''
                        ><%= typeof(schedule_description) !== 'undefined' && schedule_description || '' %></textarea>
            </div>

<div class="form-group">
<label for="schedule_description">时间规划（必填）</label>
<!-- start cron time settings input block -->
            <noscript>
                &lt;div class="alert alert-info"&gt; Your browser doesn't enable or support JavaScript. Please enable it to enjoy our features. &lt;/div&gt;
            </noscript>
            <table id="cronJobs" class="table gray table-hover">
                <tbody>
                    <tr id="editingRow">
                        <td colspan="8">
                            <form action="#" method="post" name="editCron" data-validate-elements="url, postData, name, pattern, expression, advancedSetting, timeout, failureThreshold, notifyEvery" data-validate-namespace="manage" class="form-horizontal" id="editCron" data-validate-attached="attached">
                                <!-- timesettigs table start-->
                                <table id="timeSettings" style="display: none;">
                                    <tbody>
                                        <tr>
                                            <th>分钟</th>
                                            <th>时</th>
                                            <th>日</th>
                                            <th>月</th>
                                            <th>周</th>
                                            <th>秒</th>
                                        </tr>
                                        <tr>
                                            <td>
                                                <select name="minute[]" multiple="multiple" size="12" id="minute">
                                                    <option value="0">0</option>
                                                    <option value="0">0</option>
                                                    <option value="1">1</option>
                                                    <option value="2">2</option>
                                                    <option value="3">3</option>
                                                    <option value="4">4</option>
                                                    <option value="5">5</option>
                                                    <option value="6">6</option>
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                    <option value="9">9</option>
                                                    <option value="10">10</option>
                                                    <option value="11">11</option>
                                                    <option value="12">12</option>
                                                    <option value="13">13</option>
                                                    <option value="14">14</option>
                                                    <option value="15">15</option>
                                                    <option value="16">16</option>
                                                    <option value="17">17</option>
                                                    <option value="18">18</option>
                                                    <option value="19">19</option>
                                                    <option value="20">20</option>
                                                    <option value="21">21</option>
                                                    <option value="22">22</option>
                                                    <option value="23">23</option>
                                                    <option value="24">24</option>
                                                    <option value="25">25</option>
                                                    <option value="26">26</option>
                                                    <option value="27">27</option>
                                                    <option value="28">28</option>
                                                    <option value="29">29</option>
                                                    <option value="30">30</option>
                                                    <option value="31">31</option>
                                                    <option value="32">32</option>
                                                    <option value="33">33</option>
                                                    <option value="34">34</option>
                                                    <option value="35">35</option>
                                                    <option value="36">36</option>
                                                    <option value="37">37</option>
                                                    <option value="38">38</option>
                                                    <option value="39">39</option>
                                                    <option value="40">40</option>
                                                    <option value="41">41</option>
                                                    <option value="42">42</option>
                                                    <option value="43">43</option>
                                                    <option value="44">44</option>
                                                    <option value="45">45</option>
                                                    <option value="46">46</option>
                                                    <option value="47">47</option>
                                                    <option value="48">48</option>
                                                    <option value="49">49</option>
                                                    <option value="50">50</option>
                                                    <option value="51">51</option>
                                                    <option value="52">52</option>
                                                    <option value="53" selected="selected">53</option>
                                                    <option value="54">54</option>
                                                    <option value="55">55</option>
                                                    <option value="56">56</option>
                                                    <option value="57">57</option>
                                                    <option value="58">58</option>
                                                    <option value="59">59</option>
                                                </select>
                                            </td>
                                            <td>
                                                <select name="hour[]" multiple="multiple" size="12" id="hour">
                                                    <option value="0" selected="selected">0</option>
                                                    <option value="0" selected="selected">0</option>
                                                    <option value="1" selected="selected">1</option>
                                                    <option value="2" selected="selected">2</option>
                                                    <option value="3" selected="selected">3</option>
                                                    <option value="4" selected="selected">4</option>
                                                    <option value="5" selected="selected">5</option>
                                                    <option value="6" selected="selected">6</option>
                                                    <option value="7" selected="selected">7</option>
                                                    <option value="8" selected="selected">8</option>
                                                    <option value="9" selected="selected">9</option>
                                                    <option value="10" selected="selected">10</option>
                                                    <option value="11" selected="selected">11</option>
                                                    <option value="12" selected="selected">12</option>
                                                    <option value="13" selected="selected">13</option>
                                                    <option value="14" selected="selected">14</option>
                                                    <option value="15" selected="selected">15</option>
                                                    <option value="16" selected="selected">16</option>
                                                    <option value="17" selected="selected">17</option>
                                                    <option value="18" selected="selected">18</option>
                                                    <option value="19" selected="selected">19</option>
                                                    <option value="20" selected="selected">20</option>
                                                    <option value="21" selected="selected">21</option>
                                                    <option value="22" selected="selected">22</option>
                                                    <option value="23" selected="selected">23</option>
                                                </select>
                                            </td>
                                            <td>
                                                <select name="day[]" multiple="multiple" size="12" id="day">
                                                    <option value="1" selected="selected">1</option>
                                                    <option value="1" selected="selected">1</option>
                                                    <option value="2" selected="selected">2</option>
                                                    <option value="3" selected="selected">3</option>
                                                    <option value="4" selected="selected">4</option>
                                                    <option value="5" selected="selected">5</option>
                                                    <option value="6" selected="selected">6</option>
                                                    <option value="7" selected="selected">7</option>
                                                    <option value="8" selected="selected">8</option>
                                                    <option value="9" selected="selected">9</option>
                                                    <option value="10" selected="selected">10</option>
                                                    <option value="11" selected="selected">11</option>
                                                    <option value="12" selected="selected">12</option>
                                                    <option value="13" selected="selected">13</option>
                                                    <option value="14" selected="selected">14</option>
                                                    <option value="15" selected="selected">15</option>
                                                    <option value="16" selected="selected">16</option>
                                                    <option value="17" selected="selected">17</option>
                                                    <option value="18" selected="selected">18</option>
                                                    <option value="19" selected="selected">19</option>
                                                    <option value="20" selected="selected">20</option>
                                                    <option value="21" selected="selected">21</option>
                                                    <option value="22" selected="selected">22</option>
                                                    <option value="23" selected="selected">23</option>
                                                    <option value="24" selected="selected">24</option>
                                                    <option value="25" selected="selected">25</option>
                                                    <option value="26" selected="selected">26</option>
                                                    <option value="27" selected="selected">27</option>
                                                    <option value="28" selected="selected">28</option>
                                                    <option value="29" selected="selected">29</option>
                                                    <option value="30" selected="selected">30</option>
                                                    <option value="31" selected="selected">31</option>
                                                </select>
                                            </td>
                                            <td>
                                                <select name="month[]" multiple="multiple" size="12" id="month">
                                                    <option value="1" selected="selected">1</option>
                                                    <option value="2" selected="selected">2</option>
                                                    <option value="3" selected="selected">3</option>
                                                    <option value="4" selected="selected">4</option>
                                                    <option value="5" selected="selected">5</option>
                                                    <option value="6" selected="selected">6</option>
                                                    <option value="7" selected="selected">7</option>
                                                    <option value="8" selected="selected">8</option>
                                                    <option value="9" selected="selected">9</option>
                                                    <option value="10" selected="selected">10</option>
                                                    <option value="11" selected="selected">11</option>
                                                    <option value="12" selected="selected">12</option>
                                                </select>
                                            </td>
                                            <td>
                                                <select name="weekday[]" multiple="multiple" size="12" id="weekday">
                                                    <option value="1" selected="selected">星期一</option>
                                                    <option value="2" selected="selected">星期二</option>
                                                    <option value="3" selected="selected">星期三</option>
                                                    <option value="4" selected="selected">星期四</option>
                                                    <option value="5" selected="selected">星期五</option>
                                                    <option value="6" selected="selected">星期六</option>
                                                    <option value="7" selected="selected">星期日</option>
                                                </select>
                                            </td>
                                            <td>
                                                <select name="second[]" multiple="multiple" size="12" id="second">
                                                    <option value="0" selected="selected">0</option>
                                                    <option value="30">30</option>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="6" class="small" style="background-color:#ffffff">
                                                按住 Ctrl，同时用鼠标点击，来选择或反选择多个值。
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                <!-- timesettigs table end-->
                                    <!-- <a href="/" class="btn" onclick="$(&#39;#editingRow&#39;).remove(); return false;">Cancel</a>
 -->      
                               <!--
                                <div class="form-actions">
                                    <input type="submit" name="submit" class="btn-primary btn" value="Save CronJob">
                                </div>
                                -->
                            </form>
                            <script type="text/javascript">
                            $(document).ready(function() {
                                initEditCron();
                            });
                            </script>
                        </td>
                    </tr>
                </tbody>
            </table>
<!-- end cron time settings input block -->
</div>
          </fieldset>


            <div class='editor_buttons'>
              <input type="submit" class='span-primary submit_btn' data-loading-text="提交中"
                     value="提交">
            </div>


        </form>
    <% } %>

  </div>
<!-- markdown editor -->
<%- Loader('/public/editor.min.js')
.js('/public/libs/editor/editor.js')
.js('/public/libs/webuploader/webuploader.withoutimage.js')
.js('/public/libs/editor/ext.js')
.js('/public/cron/js/index.js')
.css('/public/cron/css/theme.css')
.done(assets, config.site_static_host, config.mini_assets)
%>
<script>
  
  (function () {
    var editor = new Editor();
    editor.render($('.editor')[0]);

    // 版块选择的检查，必须选择
    $('#create_schedule_form').on('submit', function (e) {
      // 必填项验证
      var tabValue = $('#tab-value').val();
      var nameValue = $('#schedule_name').val();

      if (!tabValue) {
        alert('必须选择一个类型！');
        $('.submit_btn').button('reset');
        $('.tab-selector').css('color', 'red');
        return false;
      } else if(!nameValue){
        alert('必须添加名称！');
        $('.submit_btn').button('reset');
        $('.name_label').css('color', 'red');
        return false;
      }

    });
    // END 版块选择的检查，必须选择

    // 选择招聘版块时，给出提示
    $('#tab-value').on('change', function () {
      var $this = $(this);
      var value = $this.val();
      var warnMsg = '';
      if (value === 'daily-jobs') {
        warnMsg = '<strong>请参考<a href="#" target="_blank">《创建日计划须知》</a></strong>';
      } else if(value === 'weekly-jobs') {
        warnMsg = '<strong>请参考<a href="#" target="_blank">《创建周计划须知》</a></strong>'
      } else if(value == 'monthly-jobs'){
        warnMsg = '<strong>请参考<a href="#" target="_blank">《创建月计划须知》</a></strong>'
      }
      $('#topic_create_warn').html(warnMsg);
    });
    // END 选择招聘版块时，给出提示
  })();

</script>